﻿using System;

using Foundation;
using AppKit;

namespace BeamOff
{
	public partial class AppDelegate : NSApplicationDelegate
	{
		public AppDelegate ()
		{
		}

		public override void DidFinishLaunching (NSNotification notification)
		{
			var menu = new NSMenu ();

			var menuItem = new NSMenuItem ();
			menu.AddItem (menuItem);

			var appMenu = new NSMenu ();
			var quitItem = new NSMenuItem ("Quit " + NSProcessInfo.ProcessInfo.ProcessName, "q", (s, e) => NSApplication.SharedApplication.Terminate (menu));
			appMenu.AddItem (quitItem);

			menuItem.Submenu = appMenu;
			NSApplication.SharedApplication.MainMenu = menu;

			//提升mac os x10.10 yosemite在vmware workstation中的性能，可以设置为开机自动运行，详见：https://github.com/JasF/beamoff.git
			int mode = (int)beamSyncMode.disableBeamSync;
			Sys.CGSSetDebugOptions (mode > 0 ? 0 : 0x08000000);
			Sys.CGSDeferredUpdates (mode);

			var application = NSApplication.SharedApplication;
			application.Terminate (this);
		}

		public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
		{
			//throw new System.NotImplementedException ();
			return true;
		}
	}
}

